import 'package:flutter/material.dart';
import 'package:news_demo/Pojo/Home_Index_Pojo.dart';
import 'package:news_demo/Pojo/News_Itme_Pojo.dart';
import 'package:news_demo/View/Delect/Delect.dart';
import 'package:news_demo/View/Home/Widget/FollowWidget.dart';
import 'package:news_demo/View/Home/Widget/HotNewsWidget.dart';
import 'package:news_demo/View/Home/Widget/IndexWidget.dart';
import 'package:news_demo/View/Home/Widget/InformationWidget.dart';
import 'package:news_demo/View/Search/SearchIndex.dart';

import '../../Pojo/Email_Persion_Pojo.dart';
import 'Widget/DrawerWidget.dart';

class Home extends StatefulWidget {
  const Home({Key? key}) : super(key: key);

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {

  late Home_Index_Pojo _HIP;
  late final List<Widget> _finaly;
  late final List<Widget> _TabBaraList;
  late final List<emailPersion> _userValueList;


  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    //数据处理传入数据
    _HIP=Home_Index_Pojo(
        [
          "https://imgconvert.csdnimg.cn/aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X3BuZy9yRldWWHdpYkxHdHlTNFBmT2ljaFVlMHdQcXZXaGpwUHhEeU5EbWZWSURwTXMzM3VlWXFmMEM2Z003a2liWVpyMjE4dWdsc3htNWhGRlRMcE9pY2NmbWRyblEvNjQw?x-oss-process=image/format,png"
        ]
    );

    List<NewsItmePojo> _NewsListArray= [
      NewsItmePojo(
        "http://n.sinaimg.cn/default/1_img/upload/3933d981/674/w899h575/20210130/b066-kiksqxh1091087.jpg",
        "2023/1/2",
        "许家印：今年是关键年，恒大一定能偿还各种债务、化解风险，一定能涅槃重生。",
        "某某日报",
        "1",
      ),
      NewsItmePojo(
        "http://n.sinaimg.cn/default/1_img/upload/3933d981/674/w899h575/20210130/b066-kiksqxh1091087.jpg",
        "2023/1/2",
        "许家印：今年是关键年，恒大一定能偿还各种债务、化解风险，一定能涅槃重生。",
        "某某日报",
        "2",
      ),
      NewsItmePojo(
        "http://n.sinaimg.cn/default/1_img/upload/3933d981/674/w899h575/20210130/b066-kiksqxh1091087.jpg",
        "2023/1/2",
        "许家印：今年是关键年，恒大一定能偿还各种债务、化解风险，一定能涅槃重生。",
        "某某日报",
          "3",
      )
    ];

    //消息数据
    _userValueList=[
      emailPersion("1","姓名","2022-1","信息","https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202106%2F13%2F20210613235426_7a793.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1675333525&t=163eb4997a91fede2a5fbcd907358648"),
      emailPersion("1","姓名","2022-1","信息","https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202106%2F13%2F20210613235426_7a793.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1675333525&t=163eb4997a91fede2a5fbcd907358648"),
      emailPersion("1","姓名","2022-1","信息","https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202106%2F13%2F20210613235426_7a793.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1675333525&t=163eb4997a91fede2a5fbcd907358648"),
      emailPersion("1","姓名","2022-1","信息","https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202106%2F13%2F20210613235426_7a793.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1675333525&t=163eb4997a91fede2a5fbcd907358648"),
      emailPersion("1","姓名","2022-1","信息","https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202106%2F13%2F20210613235426_7a793.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1675333525&t=163eb4997a91fede2a5fbcd907358648"),
      emailPersion("1","姓名","2022-1","信息","https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202106%2F13%2F20210613235426_7a793.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1675333525&t=163eb4997a91fede2a5fbcd907358648"),
    ];

    _finaly=[
      //传入HomeIndexPojo数据对象
      Index(HIP:_HIP,NewsListArray: _NewsListArray),
      News(),
      Follow(),
      Information(userValueList: _userValueList,),
    ];

    _TabBaraList=[
      const Tab(text: "首页",),
      const Tab(text: "热点新闻"),
      const Tab(text: "我的关注"),
      const Tab(text: "消息"),
    ];
  }




  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
        length: _TabBaraList.length,
        child: Scaffold(
          appBar: AppBar(
            // title: ,
            backgroundColor: Colors.black,
            leading: Builder(
              builder: (context){
                return GestureDetector(
                  child: Icon(Icons.format_align_left),
                  onTap:(){
                    Scaffold.of(context).openDrawer();
                  },
                );
              },
            ),
            title: Container(
              alignment:Alignment.center,
              width: double.infinity,
              height: 40,
              child: GestureDetector(
                onTap: (){
                  Navigator.push(context, MaterialPageRoute(builder: (context)=>Search()));
                },
                child: Container(
                  alignment: Alignment.center,
                  width: 180,
                  height: 30,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border.all(width: 2,color: Colors.white38),
                    borderRadius: BorderRadius.all(Radius.circular(20))
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Container(
                        height: 30,
                        child: Text("搜索",style: TextStyle(
                          color: Colors.black,
                          fontSize: 16
                        ),
                        ),
                      ),
                      Container(
                        child: Icon(Icons.search,color: Colors.black,size: 20,),
                      )
                    ],
                  ),
                ),
              ),
            ),
            actions: [
              GestureDetector(
                onTap: (){
                  Navigator.push(context, MaterialPageRoute(builder: (contetx)=>DelectIndex()));
                },
                child: Container(
                  margin: EdgeInsets.fromLTRB(0, 0, 10.0, 0),
                  child: Icon(Icons.delete_outline,size: 28,),
                ),
              )
            ],
          ),
          body:TabBarView(
            children: _finaly,
          ),
          bottomNavigationBar: TabBar(
            tabs: _TabBaraList,
            labelColor: Colors.blue,
            unselectedLabelColor: Colors.black,

          ),
          drawer: Drawer_left(UserName: "张三",),
        ),
    );
  }
}



